package com.quinn.myDemo;
import java.util.Arrays;
import java.util.Random;

/**
 * DLTGenerator
 *
 * @author HanQuinn
 * Date: 2023/8/14
 * Time: 15:25
 */
public class DLTGenerator {
    public static void main(String[] args) {
        int[] redBalls = generateRedBalls();
        int[] blueBalls = generateBlueBalls();

        System.out.println("红色球号码：" + Arrays.toString(redBalls));
        System.out.println("蓝色球号码：" + Arrays.toString(blueBalls));
    }

    // 生成红色球号码，范围是1-35，共选取5个不重复的号码
    public static int[] generateRedBalls() {
        int[] redBalls = new int[5];
        Random random = new Random();

        for (int i = 0; i < 5; i++) {
            int ball;
            do {
                ball = random.nextInt(35) + 1;
            } while (contains(redBalls, ball));

            redBalls[i] = ball;
        }

        Arrays.sort(redBalls);
        return redBalls;
    }

    // 生成蓝色球号码，范围是1-12，共选取2个不重复的号码
    public static int[] generateBlueBalls() {
        int[] blueBalls = new int[2];
        Random random = new Random();

        for (int i = 0; i < 2; i++) {
            int ball;
            do {
                ball = random.nextInt(12) + 1;
            } while (contains(blueBalls, ball));

            blueBalls[i] = ball;
        }

        Arrays.sort(blueBalls);
        return blueBalls;
    }

    // 判断数组中是否包含某个元素
    public static boolean contains(int[] array, int num) {
        for (int i : array) {
            if (i == num) {
                return true;
            }
        }
        return false;
    }
}
